// 页面路径：store/index.js
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex); //vue的插件机制

import home from '@/store/home/index.js'
import user from "@/store/user/index.js";
import restaurant from "@/store/restaurant/index.js";


//Vuex.Store 构造器选项
const store = new Vuex.Store({
    modules: {
        home,
        user,
        restaurant
    },
    state: {
        //公共的变量，这里的变量不能随便修改，只能通过触发mutations的方法才能改变
        navBarActive: 'mine',
    },
    mutations: {
        //相当于同步的操作
        //导航栏的的显示图标显示
        CHANGENAVBAR(state, navBarChangeTargetName) {
            state.navBarActive = navBarChangeTargetName
        },

    },
    actions: {
        //相当于异步的操作,不能直接改变state的值，只能通过触发mutations的方法才能改变
        //导航栏切换
        changeNavBar({commit}, name) {
            // //自定义tabBar切换 uni.switchTab
            // uni.switchTab({
            // 	url: `../${name}/index`,
            // 	success: (e) => {
            // 		this.commit('CHANGENAVBAR', name)
            // 	},
            // 	error: (e) => {
            // 		console.log('点餐切换失败', e);
            // 	}
            // })
            this.commit('CHANGENAVBAR', name)
        },

    },
    getters: {}
})
export default store
